
package com.wgo.precise.client.ui.model;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;

/**
 * @author petterei
 *
 * @version $Id: ClientPropertyDefinition.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 */
public abstract class ClientPropertyDefinition<T> extends AbstractPropertySpesification {

	private Long identifier;
	private String label = "No label set.";
	private String description = "No description set.";
	private boolean isReadOnly = false;
	private PropertyType propertyType;
	private int position = 100;


	public ClientPropertyDefinition(Long identifier, String label, PropertyType propertyType) {
		this.identifier = identifier;
		this.label = label;
		this.propertyType = propertyType;
	}
	
	@Override
	public Long getIdentifier() {
		return identifier;
	}

	@Override
	public String getLabel() {
		return label;
	}
	
	@Override
	public void setLabel(String label) {
		this.label = label;
	}
	
	@Override
	public String getDescription() {
		return description;
	}
	
	@Override
	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isReadOnly() {
		return isReadOnly;
	}

	public void setReadOnly(boolean isReadOnly) {
		this.isReadOnly = isReadOnly;
	}

	@Override
	public PropertyType getPropertyType() {
		return propertyType;
	}

	@Override
	public int getPosition() {
		return position;
	}

	@Override
	public void setPosition(int position) {
		this.position = position;
	}

	@Override
	public CellEditor getCellEditor(Composite parent) {
		CellEditor editor = super.getCellEditor(parent);
		editor.getControl().setEnabled(!isReadOnly());
		return editor;
	}

	/**
	 * @param value can be Object, String but not PropertyValue
	 */
	protected abstract void setValue(T persistent, Object value);

	/**
	 * @return the value from the correspondig field from the domain model object
	 */
	protected abstract Object getValue(T persistent);

}
